home *** CD-ROM | disk | FTP | other *** search
- package com.ibm.uvm.awt.beaninfo;
-
- import java.beans.BeanDescriptor;
- import java.beans.BeanInfo;
- import java.beans.EventSetDescriptor;
- import java.beans.FeatureDescriptor;
- import java.beans.IntrospectionException;
- import java.beans.Introspector;
- import java.beans.MethodDescriptor;
- import java.beans.ParameterDescriptor;
- import java.beans.PropertyDescriptor;
- import java.beans.SimpleBeanInfo;
- import java.lang.reflect.Method;
- import java.text.MessageFormat;
- import java.util.ResourceBundle;
-
- public class IvjBeanInfo extends SimpleBeanInfo {
- private static ResourceBundle resabtabi = ResourceBundle.getBundle("com/ibm/uvm/awt/beaninfo/abtabi");
- public static final String BOUND = "bound";
- public static final String CONSTRAINED = "constrained";
- public static final String PROPERTYEDITORCLASS = "propertyEditorClass";
- public static final String READMETHOD = "readMethod";
- public static final String WRITEMETHOD = "writeMethod";
- public static final String DISPLAYNAME = "displayName";
- public static final String EXPERT = "expert";
- public static final String HIDDEN = "hidden";
- public static final String PREFERRED = "preferred";
- public static final String SHORTDESCRIPTION = "shortDescription";
- public static final String CUSTOMIZERCLASS = "customizerClass";
- public static final String INDEFAULTEVENTSET = "inDefaultEventSet";
- public static final String ENUMERATIONVALUES = "enumerationValues";
- public static final String ISCONTAINER = "isContainer";
- public static final String CONTAINERDELEGATE = "containerDelegate";
- public static final String OBSCURE = "ivjObscure";
- public static final String DESIGNTIMEPROPERTY = "ivjDesignTimeProperty";
-
- private static String capitalize(String s) {
- if (s.length() == 0) {
- return s;
- } else {
- char[] chars = s.toCharArray();
- chars[0] = Character.toUpperCase(chars[0]);
- return new String(chars);
- }
- }
-
- public BeanDescriptor createBeanDescriptor(Class cls, Object[] args) {
- Class customizerClass = null;
-
- for(int i = 0; i < args.length; i += 2) {
- if ("customizerClass".equals((String)args[i])) {
- customizerClass = (Class)args[i + 1];
- break;
- }
- }
-
- BeanDescriptor bd = new BeanDescriptor(cls, customizerClass);
-
- for(int i = 0; i < args.length; i += 2) {
- String key = (String)args[i];
- Object value = args[i + 1];
- this.setFeatureDescriptorValue(bd, key, value);
- }
-
- return bd;
- }
-
- public EventSetDescriptor createEventSetDescriptor(Class cls, String name, Object[] args, MethodDescriptor[] lmds, Class listenerType, String addListenerName, String removeListenerName) {
- EventSetDescriptor esd = null;
- Class[] paramTypes = new Class[]{listenerType};
-
- try {
- Method addMethod = null;
- Method removeMethod = null;
-
- try {
- addMethod = cls.getMethod(addListenerName, paramTypes);
- } catch (Exception var14) {
- this.throwError(var14, MessageFormat.format(resabtabi.getString("Cannot_get_the_meth1"), addListenerName));
- }
-
- try {
- removeMethod = cls.getMethod(removeListenerName, paramTypes);
- } catch (Exception var13) {
- this.throwError(var13, MessageFormat.format(resabtabi.getString("Cannot_get_the_meth1"), removeListenerName));
- }
-
- esd = new EventSetDescriptor(name, listenerType, lmds, addMethod, removeMethod);
- } catch (Exception var15) {
- this.throwError(var15, MessageFormat.format(resabtabi.getString("Cannot_create_the_E1"), name));
- }
-
- for(int i = 0; i < args.length; i += 2) {
- String key = (String)args[i];
- Object value = args[i + 1];
- if ("inDefaultEventSet".equals(key)) {
- esd.setInDefaultEventSet((Boolean)value);
- } else {
- this.setFeatureDescriptorValue(esd, key, value);
- }
- }
-
- return esd;
- }
-
- public MethodDescriptor createMethodDescriptor(Class cls, String name, Object[] args, ParameterDescriptor[] params, Class[] paramTypes) {
- MethodDescriptor md = null;
-
- try {
- Method aMethod = null;
-
- try {
- aMethod = cls.getMethod(name, paramTypes);
- } catch (Exception var10) {
- this.throwError(var10, MessageFormat.format(resabtabi.getString("Cannot_get_Method_f1"), name));
- }
-
- if (paramTypes.length > 0) {
- md = new MethodDescriptor(aMethod, params);
- } else {
- md = new MethodDescriptor(aMethod);
- }
- } catch (Exception var11) {
- this.throwError(var11, MessageFormat.format(resabtabi.getString("Cannot_create_Metho"), name));
- }
-
- for(int i = 0; i < args.length; i += 2) {
- String key = (String)args[i];
- Object value = args[i + 1];
- this.setFeatureDescriptorValue(md, key, value);
- }
-
- return md;
- }
-
- private PropertyDescriptor createOtherPropertyDescriptor(String name, Class cls) throws IntrospectionException {
- Method readMethod = null;
- Method writeMethod = null;
- String base = capitalize(name);
- Class[] parameters = new Class[0];
-
- try {
- readMethod = cls.getMethod("is" + base, parameters);
- } catch (Exception var9) {
- }
-
- if (readMethod == null) {
- try {
- readMethod = cls.getMethod("get" + base, parameters);
- } catch (Exception var8) {
- readMethod = findMethod(cls, "get" + base, 0);
- }
- }
-
- if (readMethod == null) {
- writeMethod = findMethod(cls, "set" + base, 1);
- } else {
- parameters = new Class[]{readMethod.getReturnType()};
-
- try {
- writeMethod = cls.getMethod("set" + base, parameters);
- } catch (Exception var7) {
- }
- }
-
- if (readMethod == null && writeMethod == null) {
- throw new IntrospectionException(MessageFormat.format(resabtabi.getString("Cannot_find_the_acc1"), name));
- } else {
- return new PropertyDescriptor(name, readMethod, writeMethod);
- }
- }
-
- public ParameterDescriptor createParameterDescriptor(String name, Object[] args) {
- ParameterDescriptor pd = null;
-
- try {
- pd = new ParameterDescriptor();
- } catch (Exception var7) {
- this.throwError(var7, MessageFormat.format(resabtabi.getString("Cannot_create_Param1"), name));
- }
-
- ((FeatureDescriptor)pd).setName(name);
-
- for(int i = 0; i < args.length; i += 2) {
- String key = (String)args[i];
- Object value = args[i + 1];
- this.setFeatureDescriptorValue(pd, key, value);
- }
-
- return pd;
- }
-
- public PropertyDescriptor createPropertyDescriptor(Class cls, String name, Object[] args) {
- PropertyDescriptor pd = null;
-
- try {
- pd = new PropertyDescriptor(name, cls);
- } catch (IntrospectionException var13) {
- try {
- pd = this.createOtherPropertyDescriptor(name, cls);
- } catch (IntrospectionException var12) {
- this.throwError(var12, MessageFormat.format(resabtabi.getString("Cannot_create_the_P1"), name));
- }
- }
-
- this.setFeatureDescriptorValue(pd, "displayName", name);
-
- for(int i = 0; i < args.length; i += 2) {
- String key = (String)args[i];
- Object value = args[i + 1];
- if ("bound".equals(key)) {
- pd.setBound((Boolean)value);
- } else if ("constrained".equals(key)) {
- pd.setConstrained((Boolean)value);
- } else if ("propertyEditorClass".equals(key)) {
- pd.setPropertyEditorClass((Class)value);
- } else if ("readMethod".equals(key)) {
- String methodName = (String)value;
-
- try {
- cls.getMethod(methodName);
- } catch (Exception var11) {
- this.throwError(var11, MessageFormat.format(resabtabi.getString("{0}_no_read_method_"), cls, methodName));
- }
- } else if ("writeMethod".equals(key)) {
- String methodName = (String)value;
-
- try {
- Class type = pd.getPropertyType();
- cls.getMethod(methodName, type);
- } catch (Exception var10) {
- this.throwError(var10, MessageFormat.format(resabtabi.getString("{0}_no_write_method"), cls, methodName));
- }
- } else {
- this.setFeatureDescriptorValue(pd, key, value);
- }
- }
-
- return pd;
- }
-
- public static Method findMethod(Class aClass, String methodName, int parameterCount) {
- try {
- Method[] methods = aClass.getMethods();
-
- for(int index = 0; index < methods.length; ++index) {
- Method method = methods[index];
- if (method.getParameterTypes().length == parameterCount && method.getName().equals(methodName)) {
- return method;
- }
- }
-
- return null;
- } catch (Throwable var6) {
- return null;
- }
- }
-
- public BeanInfo[] getAdditionalBeanInfo() {
- Class superClass = ((SimpleBeanInfo)this).getBeanDescriptor().getBeanClass().getSuperclass();
- if (superClass != null) {
- BeanInfo superBeanInfo = null;
-
- try {
- superBeanInfo = Introspector.getBeanInfo(superClass);
- } catch (IntrospectionException var4) {
- return null;
- }
-
- if (superBeanInfo != null) {
- BeanInfo[] ret = new BeanInfo[1];
- ret[0] = superBeanInfo;
- return ret;
- }
- }
-
- return null;
- }
-
- public int getDefaultEventIndex() {
- return -1;
- }
-
- public int getDefaultPropertyIndex() {
- return -1;
- }
-
- public void handleException(Throwable exception) {
- System.out.println(resabtabi.getString("UNCAUGHT_EXC"));
- exception.printStackTrace(System.out);
- }
-
- private void setFeatureDescriptorValue(FeatureDescriptor fd, String key, Object value) {
- if ("displayName".equals(key)) {
- fd.setDisplayName((String)value);
- } else if ("expert".equals(key)) {
- fd.setExpert((Boolean)value);
- } else if ("hidden".equals(key)) {
- fd.setHidden((Boolean)value);
- } else if ("preferred".equals(key)) {
- fd.setValue(key, value);
- } else if ("shortDescription".equals(key)) {
- fd.setShortDescription((String)value);
- } else {
- fd.setValue(key, value);
- }
-
- }
-
- protected void throwError(Exception e, String s) {
- throw new Error(((Throwable)e).toString() + " " + s);
- }
- }
-